<template>
  <div class="theme-manager">
    <div class="theme-toggle" @click="togglePanel">
      <span>🎨</span>
    </div>
    
    <div v-if="showPanel" class="theme-panel">
      <div class="panel-header">
        <h3>主题设置</h3>
        <button @click="togglePanel">×</button>
      </div>
      
      <div class="panel-content">
        <div class="current-theme">
          <div class="color-preview" :style="{ backgroundColor: theme.currentTheme }">
            <span>{{ theme.currentTheme }}</span>
          </div>
        </div>
        
        <div class="preset-themes">
          <h4>预设主题</h4>
          <div class="theme-grid">
            <button
              v-for="(color, name) in theme.presetThemes"
              :key="name"
              class="theme-btn"
              :style="{ backgroundColor: color }"
              @click="theme.setPresetTheme(name)"
            ></button>
          </div>
        </div>
        
        <div class="custom-color">
          <h4>自定义颜色</h4>
          <input
            type="color"
            :value="theme.currentTheme"
            @input="e => theme.setTheme(e.target.value)"
          />
        </div>
        
        <div class="actions">
          <button @click="theme.setRandomTheme">随机</button>
          <button @click="theme.resetTheme">重置</button>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import { useTheme } from '@/hooks'

const theme = useTheme('#ffffff')
const showPanel = ref(false)

const togglePanel = () => {
  showPanel.value = !showPanel.value
}
</script>

<style scoped>
.theme-manager {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 1000;
}

.theme-toggle {
  width: 50px;
  height: 50px;
  background: #409eff;
  color: white;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 20px;
}

.theme-panel {
  position: absolute;
  top: 60px;
  right: 0;
  width: 280px;
  background: white;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  border: 1px solid #e4e7ed;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px;
  border-bottom: 1px solid #e4e7ed;
}

.panel-header h3 {
  margin: 0;
  font-size: 16px;
}

.panel-header button {
  background: none;
  border: none;
  font-size: 20px;
  cursor: pointer;
  color: #909399;
}

.panel-content {
  padding: 16px;
}

.current-theme {
  margin-bottom: 16px;
}

.color-preview {
  width: 100%;
  height: 60px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-weight: bold;
  text-shadow: 0 1px 2px rgba(0,0,0,0.3);
}

.preset-themes h4,
.custom-color h4 {
  margin: 0 0 12px 0;
  font-size: 14px;
  color: #606266;
}

.theme-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 16px;
}

.theme-btn {
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  border: 2px solid transparent;
}

.theme-btn:hover {
  border-color: #409eff;
}

.custom-color input {
  width: 100%;
  height: 40px;
  border: 1px solid #dcdfe6;
  border-radius: 4px;
  cursor: pointer;
}

.actions {
  display: flex;
  gap: 8px;
  margin-top: 16px;
}

.actions button {
  flex: 1;
  padding: 8px 16px;
  border: 1px solid #dcdfe6;
  background: white;
  border-radius: 4px;
  cursor: pointer;
}

.actions button:hover {
  background: #f5f7fa;
}
</style> 